<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Insert title here</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Hello, Bootstrap Table!</title>
	<meta charset="UTF-8">
	<title>Title</title>
	<script th:src="@{/js/jquery-3.2.1.min.js}"></script>
	<!-- 最新 Bootstrap4 核心 CSS 文件 -->
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
	<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
	<script	th:src="@{/js/bootstrap.bundle.min.js} " rel="stylesheet"></script>
	<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
	<script	th:src="@{/js/bootstrap.min.js}"rel="stylesheet"> </script>

	<link rel="stylesheet" href="https://cdn.bootcss.com/jquery.bootstrapvalidator/0.5.3/css/bootstrapValidator.min.css">
	<script type="text/javascript" src="https://cdn.bootcss.com/jquery.bootstrapvalidator/0.5.3/js/bootstrapValidator.min.js"></script>
	<script th:src="@{/js/functions.js}"></script>

</head>
<body>
<!-- 顶栏 -->
<div th:include="../templates/admin/top::headtop"></div>
<!-- 中间主体 -->
<div class="container" id="content">
	<div class="row">
		<div th:include="../templates/admin/menu::headmenu"></div>
		<div class="col-md-10">
			<div class="panel panel-default">
				<div class="panel-heading">
					<div class="row">
						<h1 class="col-md-5">商品管理</h1>
							<form class="form-inline" id="searchForm" th:action="@{/goods/findGoods}" method="post">
								<div class="form-group col-md-2 offset-1">
									<input class="form-control input-sm" id="name" name="name" placeholder="商品名" type="text" th:value="${param.name}"/>
								</div>
								<div class="form-group col-md-1">
									<button class="btn btn-primary btn-sm" type="submit">搜索</button>
								</div>
							</form>
						<div class="form-group col-md-1">
							<button onclick="addMadel()" class="btn btn-primary btn-sm" type="submit">新增商品</button>
						</div>
					</div>
				</div>
				<table class="table table-bordered">
					<thead>
					<tr>
					<tr>
						<th>选项</th>
						<th>商品号</th>
						<th>商品名</th>
						<th>价格</th>
						<th>图片</th>
						<th>数量</th>
						<th>类型</th>
						<th>操作</th>
					</tr>

					</tr>
					</thead>
					<tbody>
					<tr th:each="goods,stat:${goods}">
						<td style="padding-top: 75px"><input name="chk" th:value="${goods.shop_id}" type="checkbox"/></td>
						<td style="padding-top: 75px" th:text="${goods.shop_id}"></td>
						<td style="padding-top: 75px" th:text="${goods.shop_name}"></td>
						<td style="padding-top: 75px" th:text="${goods.shop_price}"></td>
						<td style="width: 167px;height: 160px"><img th:src="${goods.shop_pic}" style="width: 167px;height: 160px"/></td>
						<td style="padding-top: 75px" th:text="${goods.remain}"></td>
						<td style="padding-top: 75px" th:text="${goods.shop_type}"></td>
						<td style="padding-top: 75px">
							<button class="btn btn-default btn-xs btn-danger btn-primary" th:onclick="cGoods([[${goods.shop_id}]])">修改</button>
							<button class="btn btn-default btn-xs btn-danger btn-primary" th:onclick="deleteGoods([[${goods.shop_id}]])">删除</button>
						</td>
					</tr>
					</tbody>
				</table>
			</div>

		</div>
	</div>
</div>
<div class="modal fade" id="register" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					增加商品
				</h4>
			</div>
			<div class="modal-body">
				<form id="bjy-form" class="form-inline">
					<table class="table">
						<tbody>
						<tr>
							<td>商品名</td>
							<td><input type="text" class="form-control" name="name" placeholder="请输入商品名"/></td>
						</tr>
						<tr>
							<td>商品价格</td>
							<td><input type="text" class="form-control" name="price" placeholder="请输入价格"/></td>
						</tr>
						<tr>
							<td>上传图片</td>
							<td><input type="file" name="file"/></td>
						</tr>
						<tr>
							<td>商品数量</td>
							<td><input type="text" class="form-control" name="remain" placeholder="请输数量"/></td>
						</tr>

						<tr>
							<td>商品类别</td>
							<td><input type="text" class="form-control" name="type" placeholder="请输类别"/></td>

						</tr>
						<tr>
							<td><button class="btn btn-default" type="button" onclick="add()">确定</button></td>
						</tr>
						</tbody>
					</table>
				</form>

			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="change" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabe">
					修改商品
				</h4>
			</div>
			<div class="modal-body">
				<form id="bjy-for" class="form-inline">
					<table class="table">
						<tbody>
						<tr>
							<td>商品ID</td>
							<td><input type="text" id="aaa" class="form-control" name="id"/></td>
						</tr>
						<tr>
							<td>商品名</td>
							<td><input type="text" class="form-control" name="name" placeholder="请输入商品名"/></td>
						</tr>
						<tr>
							<td>商品价格</td>
							<td><input type="text" class="form-control" name="price" placeholder="请输入价格"/></td>
						</tr>
						<tr>
							<td>商品数量</td>
							<td><input type="text" class="form-control" name="remain" placeholder="请输数量"/></td>
						</tr>

						<tr>
							<td>商品类别</td>
							<td><input type="text" class="form-control" name="type" placeholder="请输类别"/></td>

						</tr>
						<tr>
							<td><button class="btn btn-default" type="button" onclick="change()">确定</button></td>
						</tr>
						</tbody>
					</table>
				</form>

			</div>
		</div>
	</div>
</div>



<script type="text/javascript">

	function deleteGoods(id) {
		console.log(id)
		$.ajax({
			type:"get",
			url:"http://localhost:8089/springbootdemo/goods/delGoods",
			data:"id="+id,
			success:function (data) {
				console.log(data)
				alert("删除成功")
				$(location).attr('href','http://localhost:8089/springbootdemo/goods/getGoods')
			},
			error:function () {
				alert("删除失败")
			}
		})
	}

	function deleteG(id){
		console.log(id)
		$.ajax({
			type:"get",
			url:"http://localhost:8089/springbootdemo/goods/delGoods",
			data:"id="+id,
			success:function (data) {
				console.log(data)
			},
			error:function () {
				alert("删除失败")
			}
		})
	}

	function add() {
		var formData = new FormData($("#bjy-form")[0])
		$.ajax({
			type:"post",
			url:"http://localhost:8089/springbootdemo/goods/addGoods",
			data: formData,
			async:false,
			cache:false,
			contentType:false,
			processData: false,
			success:function (data) {
				console.log(data)
				alert("添加成功")
				window.location.reload()
				$(location).attr('href','http://localhost:8089/springbootdemo/goods/getGoods')
			},
			error:function (){
				alert("错误")
			}
		})
	}

	function change() {
		var formData = new FormData($("#bjy-for")[0])
		$.ajax({
			type:"post",
			url:"http://localhost:8089/springbootdemo/goods/changeGoods",
			data: formData,
			async:false,
			cache:false,
			contentType:false,
			processData: false,
			success:function (data) {
				console.log(data)
				alert("修改成功")
				window.location.reload()
				$(location).attr('href','http://localhost:8089/springbootdemo/goods/getGoods')
			},
			error:function (){
				alert("错误")
			}
		})
	}
	function Updata(userid){

		window.location=getContextPath()+"/admin/findIdUser?user_id="+userid;
		// $.post("./findIdUser",{userid : userid}, function (data) {
		//     window.location.reload();
		// });
	}

	function addMadel() {
		$("#register").modal("show");
	}

	function cGoods(id) {
		$("#change").modal("show");
		$("#aaa").val(id)
	}
</script>
</body>
</html>